<?php 
	session_start();
	$var1= $_SESSION["registrado"];
	$var2= $_SESSION["administrador"];
	if ($var1 == null): {
		echo ("User not registered");
	} elseif ($var2 == 0): { 
			echo ("User without permissions");
	} else : {
?>


<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.css" rel="stylesheet"	media="screen">

<title>My project manager</title>

<style type="text/css">
  body {
    padding-top: 60px;
    padding-bottom: 40px;
  }
  .sidebar-nav {
    padding: 9px 0;
  
  }
    .container {
    padding-top: 100px;
  }

    .finish {
    padding-top: 250px;
    padding-right: 25px;
    padding-left: 25px;
  }
  

  
  @media (max-width: 980px) {
    /* Enable use of floated navbar text */
    .navbar-text.pull-right {
      float: none;
      padding-left: 5px;
      padding-right: 5px;
    }
  }
</style>

</head>

<body>
<?php include ('configuration.php'); ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>
    
<div class="span12">
<div class="navbar navbar-inverse navbar-fixed-top">
	<div class="navbar-inner">
		<div class="container-fluid">
			<button type="button" class="btn btn-navbar" data-toggle="collapse"
				data-target=".nav-collapse">
				<span class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="brand"href="http://localhost/bases--grupo10/homeAdmin.php?">My project manager</a>
			<div class="nav-collapse collapse">
				<p class="navbar-text pull-right">
				
					<a href="http://localhost/bases--grupo10/logout.php?" class="navbar-link">Log out</a>
				</p>
				<ul class="nav">
					<li class="active"><a href="http://localhost/bases--grupo10/homeAdmin.php?">Home</a></li>
					<li><a href="http://localhost/bases--grupo10/about.php?">About</a></li>
					<li><a href="http://localhost/bases--grupo10/contact.php?">Contact</a></li>
				</ul>
			</div>
		</div>
	</div>
</div>
</div>
   

    <?php
    $name=$_POST['name'];
    $surnames=$_POST['surnames'];
    $email=$_POST['email'];
    $id=$_POST['id'];
    $no_actualizar=0;
    
    if(empty($name) || empty($surnames)) {
         $no_actualizar=1;
     }
    //compruebo que el nombre y apellidos no tengan mas longitud de la adecuada
   if(strlen($name)>15) {          
      $no_actualizar=1;   
   }
   if(strlen($surnames)>35) {
      $no_actualizar=1;
    } 

    if ($no_actualizar==1){
        echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> There are wrong fields and the user can´t be modify</u></font></h1>";
        echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyMember.php?' style='position:absolute;top:250px;left:50px'>Back</a>";

    }else {
        $no_actualizar=0;
    
    //actualizo los datos
    //si el email es null y es responsable de algun proyecto, no puedo actualizarlo a null
    if ($email==null) { 
    //consulto si es responsable de algun proyecto, porque si lo es, el mail no puede estar a null
        $q = mysql_query("SELECT pr.mail_member FROM participate p, project_member pr WHERE p.id_member_participate = pr.id_member
                            AND p.is_responsible =1 AND pr.id_member ='$id'");
        $result1 = mysql_result($q, 0);  //0, coge el primer resultado de la query
        if ($result1!=null){
            //es responsable de algun proyecto, asi q no puedo actualizar el mail a null
            $no_actualizar=1;
            echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> Mail can't be null because $name $surnames is responsible for a project</u></font></h1>"; 
            echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyMember.php?' style='position:absolute;top:250px;left:50px'>Back</a>";
            
        }
        else{
            $q1 = mysql_query("UPDATE project_member SET name_member='$name', surnames_member='$surnames', mail_member='$email' where id_member='$id'");        
        }
    }else{ //si el mail es distinto de null, puedo actualizarlo en cualquier caso
        $q1 = mysql_query("UPDATE project_member SET name_member='$name', surnames_member='$surnames', mail_member='$email' where id_member='$id'");
    }
    
    
    
    echo "
	<div class='span12'>
	    <h1 class='muted''>Modify member</h1>
        <h1 >Member $name changed </h1>
    </div>	
    ";
    
    if ($no_actualizar!=1): {
    ?>
    <div class="finish">  
            <a class="btn btn-primary " type="button" href="http://localhost/bases--grupo10/modifyMember.php?" >Modify more</a>
            <a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/homeAdmin.php?" >Finish</a>
    </div>
    <?php }endif;?>
    
</body>
</html>   

<?php 
}
}endif;?>